package View.Add;

import Hander.Add.AddProjectPersonnelViewHander;
import View.LeaderView;
import entity.ProjectPersonnelTable;

import javax.swing.*;
import java.awt.*;
import java.sql.Date;

public class AddProjectPersonnelView extends JDialog {
    private String tableName;
    private JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 20));


    //JLabel projectpersonnelIDLabel = new JLabel("projectpersonnelIDLabel:", JLabel.RIGHT);
    //JTextField projectpersonnelIDField = new JTextField();

    JLabel projectIDLabel = new JLabel("projectID:", JLabel.RIGHT);
    JTextField projectIDField = new JTextField();
    JLabel personnelIDLabel = new JLabel("personnelID:", JLabel.RIGHT);
    JTextField personnelIDField = new JTextField();
    JLabel roleLabel = new JLabel("role:", JLabel.RIGHT);
    JTextField roleField = new JTextField();
    JLabel startDateLabel = new JLabel("startDate:", JLabel.RIGHT);
    JTextField startDateField = new JTextField();
    JLabel endDateLabel = new JLabel("endDate:", JLabel.RIGHT);
    JTextField endDateField = new JTextField();
    JButton addBtn = new JButton("添加");
    AddProjectPersonnelViewHander addProjectPersonnelViewHander;

    public AddProjectPersonnelView(LeaderView leaderView, String tableName) {
        super(leaderView, "添加部门信息", true);

        setTableName(tableName);
        addProjectPersonnelViewHander = new AddProjectPersonnelViewHander(this, leaderView);
//
//        projectpersonnelIDLabel.setPreferredSize(new Dimension(120, 20));
//        jPanel.add(projectpersonnelIDLabel);
//        projectpersonnelIDField.setPreferredSize(new Dimension(200, 20));
//        jPanel.add(projectpersonnelIDField);
//
//

        projectIDLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(projectIDLabel);
        projectIDField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(projectIDField);

        personnelIDLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(personnelIDLabel);
        personnelIDField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(personnelIDField);

        roleLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(roleLabel);
        roleField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(roleField);

        startDateLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(startDateLabel);
        startDateField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(startDateField);

        endDateLabel.setPreferredSize(new Dimension(120, 20));
        jPanel.add(endDateLabel);
        endDateField.setPreferredSize(new Dimension(200, 20));
        jPanel.add(endDateField);



        addBtn.addActionListener(addProjectPersonnelViewHander);
        jPanel.add(addBtn);

        Container contentPane = getContentPane();
        contentPane.add(jPanel);

        setSize(400, 350);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setVisible(true);
    }

    public ProjectPersonnelTable buildDepartment() {
        ProjectPersonnelTable projectPersonnelTable = new ProjectPersonnelTable();
        projectPersonnelTable.setProjectPersonnelID(0);
        projectPersonnelTable.setProjectID(Integer.valueOf(projectIDField.getText()));
        projectPersonnelTable.setPersonnelID(Integer.valueOf(personnelIDField.getText()));
        projectPersonnelTable.setRole(roleField.getText());
        projectPersonnelTable.setStartDate(Date.valueOf(startDateField.getText()));
        projectPersonnelTable.setEndDate(Date.valueOf(endDateField.getText()));
        return projectPersonnelTable;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }
}
